package io.kiki.sba.registry.server.data_store.slot;

import io.kiki.sba.registry.server.data_store.cache.DatumStorageDelegate;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


public class SlotChangeListenerManager {

    private final List<SlotChangeListener> localSlotChangeListeners = new ArrayList<>();

    private final List<SlotChangeListener> remoteSlotChangeListeners = new ArrayList<>();

    @Resource
    private DatumStorageDelegate datumStorageDelegate;

    @PostConstruct
    public void init() {
        localSlotChangeListeners.add(datumStorageDelegate.getSlotChangeListener(true));

        remoteSlotChangeListeners.add(datumStorageDelegate.getSlotChangeListener(false));
    }

    public List<SlotChangeListener> localUpdateListeners() {
        return new ArrayList<>(localSlotChangeListeners);
    }

    public List<SlotChangeListener> remoteListeners() {
        return new ArrayList<>(remoteSlotChangeListeners);
    }


    public void setDatumStorageDelegate(DatumStorageDelegate datumStorageDelegate) {
        this.datumStorageDelegate = datumStorageDelegate;
        init();
    }
}
